﻿using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.SharePoint.Explorer;
using Microsoft.VisualStudio.SharePoint.Explorer.Extensions;
using Microsoft.VisualStudio.SharePoint;
using System.Windows.Forms;

namespace CodeCounsel.SharePoint.DevTools.ExplorerNodeExtensions
{
    [Export(typeof(IExplorerNodeTypeExtension))]
    [ExplorerNodeType(ExtensionNodeTypes.FieldNode)]
    public class ContentTypeFieldNodeExtension
        : IExplorerNodeTypeExtension
    {
        public void Initialize(IExplorerNodeType nodeType)
        {
            nodeType.NodeMenuItemsRequested +=
                delegate(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
                {
                    IMenuItem copyIDMenuItem = e.MenuItems.Add("Copy ID");
                    copyIDMenuItem.Click +=
                        delegate
                        {
                            IFieldNodeInfo nodeInfo = e.Node.GetAnnotation<IFieldNodeInfo>();
                            Clipboard.SetData(DataFormats.Text, nodeInfo.Id.ToString("B"));
                        };
                };
        }
    }
}
